package top.wangjingxin.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;
import org.springframework.util.FileCopyUtils;
import top.wangjingxin.dao.ConfigDao;

import javax.annotation.PostConstruct;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;

@Component
public class AppConfig {
    @Autowired
    ConfigDao configDao;
    public static String config;
    public static final Integer MAX_ROWS = 100;
    public static volatile String ROOT = null;

    @PostConstruct
    public void config() {
        ROOT = configDao.root();
        String filePath = "config.json";//类路径，编译后classes目录下
        Resource resource = new ClassPathResource(filePath);
        try {
            config = FileCopyUtils.copyToString(new InputStreamReader(new FileInputStream(resource.getFile()),"utf8"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
